package net.fdukedom.o3i.util;

/**
 * Implements some trivial operations with data.
 * 
 * @author duke
 */
public class NumberUtil {

    /**
     * Converts to bytes to short.
     * 
     * @param high high byte
     * @param low low byte
     * 
     * @return short result
     */
    public static short convertToShort(byte high, byte low) {
        int sequenceNumber = high * 256 + low;
        return (short) sequenceNumber;
    }    
    
    /**
     * Converts short to byte array.
     * 
     * @param value value to be converted
     * 
     * @return array with high byte at position 0, and low byte at position 1
     */
    public static byte[] convertToByteArray(short value) {
        byte[] result = new byte[2];
        result[0] = (byte) (value % 256);
        result[1] = (byte) (value - result[0] * 256);
        return result;
    }
    
}
